﻿using VirtualTournaments.DataAccess.SqlServer.DataMappers;

namespace VirtualTournaments.DataAccess.SqlServer.DataProxies
{
	internal class PodiumDataProxy : Business.Bets.Podium
	{
		internal PodiumDataProxy(SqlServer.TournamentPodiumBetTarget dataObject)
			: base(null, null, null)
		{
			InnerDataObject = dataObject;
		}

		internal SqlServer.TournamentPodiumBetTarget InnerDataObject { get; set; }

		#region Override properties

		internal bool FirstHasBeenRead { get; set; }
		public override Business.Tournaments.Team First
		{
			get
			{
				if (!FirstHasBeenRead)
				{
					FirstHasBeenRead = true;
					if (base.First == null)
					{
						base.First = MapFirst();
					}
				}
				return base.First;
			}
		}

		internal bool SecondHasBeenRead { get; set; }
		public override Business.Tournaments.Team Second
		{
			get
			{
				if (!SecondHasBeenRead)
				{
					SecondHasBeenRead = true;
					if (base.Second == null)
					{
						base.Second = MapSecond();
					}
				}
				return base.Second;
			}
		}

		internal bool ThirdHasBeenRead { get; set; }
		public override Business.Tournaments.Team Third
		{
			get
			{
				if (!ThirdHasBeenRead)
				{
					ThirdHasBeenRead = true;
					if (base.Third == null)
					{
						base.Third = MapThird();
					}
				}
				return base.Third;
			}
		}

		private Business.Tournaments.Team MapFirst()
		{
			return TeamsDataMapper.Instance.DataObject2BusinessObject(InnerDataObject.FirstTeam);
		}

		private Business.Tournaments.Team MapSecond()
		{
			return TeamsDataMapper.Instance.DataObject2BusinessObject(InnerDataObject.SecondTeam);
		}

		private VirtualTournaments.Business.Tournaments.Team MapThird()
		{
			return TeamsDataMapper.Instance.DataObject2BusinessObject(InnerDataObject.ThirdTeam);
		}

		#endregion
	}
}
